package com.zx.ishopping.controller.admin;

import com.zx.ishopping.DTO.UserPageQueryDTO;

import com.zx.ishopping.DTO.UserInfoDTO;
import com.zx.ishopping.VO.UserVo;
import com.zx.ishopping.results.PageResult;
import com.zx.ishopping.results.Result;
import com.zx.ishopping.services.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminUserController")
@RequestMapping("/admin/user")

public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 管理员用户添加用户
     * @param userInfoDTO 用户数据
     * @return User
     */
    @PostMapping("/register")
    public Result register(@RequestBody UserInfoDTO userInfoDTO){
        log.info("用户注册开始{}："+userInfoDTO);
        userService.register(userInfoDTO);
        return Result.success();
    }


    /**
     * 管理员用户更新用户信息
     * @param userInfoDTO
     * @return
     */
    @PutMapping("/updateUser")
    public Result updateUser(@RequestBody UserInfoDTO userInfoDTO){
        userService.update(userInfoDTO);
        return Result.success();
    }

    /**
     *员工信息分页查询
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/userQuery")
    public Result<PageResult> pageQuery(UserPageQueryDTO userPageQueryDTO) {
        PageResult pageResult = new PageResult();
        pageResult = userService.pageQuery(userPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询用户信息
     */
    @GetMapping("/getUserById")
    public Result<UserVo> getUserById(Long id){
        UserVo userVo = new UserVo();
        userVo = userService.getUserById(id);
        return Result.success(userVo);
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @DeleteMapping("/deleteUser")
    public Result deleteUser(long id){
        userService.deleteUser(id);
        return Result.success();
    }

    



}
